import { createRouter, createWebHashHistory } from 'vue-router'
const Layout = () => import('@/views/Layout')
const Home = () => import('@/views/home/index')
const Search = () => import('@/views/search/index')
const Details = () => import('@/views/details/index')
const Login = () => import('@/views/login/index')
const KnowLedge = () => import('@/views/knowledge/index')
const lanting = () => import('@/views/lanting/index')
const knowledgeDetail = () => import('@/views/knowledge/knowledgeDetail/index')
const showResult = () => import('@/views/lanting/components/showResult.vue')
const copybook = () => import('@/views/copybook/index.vue')
const artistList = () => import('@/views/home/components/artistList.vue')
const artistListDetail = () => import('@/views/home/components/artistListDetail.vue')

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      { path: '/', component: Home },
      { path: '/search', component: Search },
      {
        path: '/knowledge',
        component: KnowLedge,
        meta: {
          keepAlive: true,
          title: '书法百科'
        }
      },
      {
        path: '/lanting',
        component: lanting,
        meta: {
          keepAlive: true,
          title: '兰亭简介'
        }
      },
      {
        path: '/knowledgeDetail',
        name: 'KnowledgeDetail',
        component: knowledgeDetail,
        meta: {
          keepAlive: true,
          title: '书法知识详情'
        }
      },
      {
        path: '/copybook',
        name: 'Copybook',
        component: copybook,
        meta: {
          keepAlive: true,
          title: '书法字帖'
        }
      },
      {
        path: '/artistListDetail',
        name: 'artistListDetail',
        component: artistListDetail,
        meta: {
          keepAlive: true,
          title: '书法家详情'
        }
      }
    ]
  },
  { path: '/details', component: Details },
  { name: 'lt-login', path: '/login', component: Login },
  { name: 'showResult', path: '/showResult', component: showResult },
  { name: 'artistList', path: '/artistList', component: artistList }
]

const router = createRouter({
  history: createWebHashHistory(),
  // 刷新页面回到顶部
  scrollBehavior (to, from, savedPosition) {
    return {
      x: 0,
      y: 0
    }
  },
  routes
})
// 跳转页面回到最顶部
router.afterEach(() => {
  window.scrollTo(0, 0)
})

export default router
